package com.example.capsule_chat0322.utils;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Looper;
import android.widget.Toast;

import com.example.capsule_chat0322.R;

/**
 * @Author zhuzhiming
 * @Date 2022/5/2 19:14
 */
public class AlterUtils {

    public static void alertByDialog(Context context, String title, String message,
                                     String positiveText, DialogInterface.OnClickListener positiveListener,
                                     String neutralText, DialogInterface.OnClickListener neutralListener) {

        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setTitle(title);
        builder.setIcon(R.drawable.self);
        builder.setMessage(message);
        builder.setPositiveButton(positiveText, positiveListener)
                .setNeutralButton(neutralText, neutralListener);
        AlertDialog dialog = builder.create();
        dialog.show();
    }

    public static void alertByToastInSonThread(Context context, String message) {
        Looper.prepare();
        Toast.makeText(context, message, Toast.LENGTH_LONG).show();
        Looper.loop();
    }

    public static void alertByToastInMainThread(Context context, String message) {
        Toast.makeText(context, message, Toast.LENGTH_LONG).show();
    }

    public static void alertByShortToastInSonThread(Context context, String message) {
        Looper.prepare();
        Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
        Looper.loop();
    }

}
